package com.zhongy.util.util.mail;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;



/**
 * 发送邮件
 * @author ym
 *
 * @createat 2013-10-31 下午01:33:02
 */
public class MailUtil {

	public static String send(String title, String content, String[] emailAddr)
			throws EmailException {
		
		
		String from = "";//// 邮件发送的邮箱
		String host = "smtp.qq.com";// smtp的地址smtp.mxhichina.com
		String username ="杭州科技网";//;// 邮件发送都显示名
		String password ="";// 发送的邮件密码
		HtmlEmail email = new HtmlEmail();

		email.setHostName(host); 
		email.setAuthentication(from, password);
		if (emailAddr != null && emailAddr.length >= 1) {
			for (int i = 0; i < emailAddr.length; i++) {
				if (i < 2) {
					email.addTo(emailAddr[i]);
				} else {
					email.addBcc(emailAddr[i]);
				}
			}
		}
		email.setFrom(from, username);// 发送的邮箱 lastpk@126.com
		email.setSubject(title);
		email.setCharset("UTF-8");// 编码格式
		email.setHtmlMsg("<html>" + content + "</html>");
		email.setTextMsg("Your email client does not support HTML messages");

		String aa = email.send();
		return aa;
	}

	public static void main(String[] args) throws EmailException {
		// TODO Auto-generated method stub
		String[] emailAddr = { "dalianlin@foxmail.com" };
		String content="测试内容";
		System.out.println(content);
		String aa = send("测试邮件", content, emailAddr);
		//System.out.println("发送成功==" + aa);

	}
}
